Skip to content

🧪 add tests for yearInReviewUtils functions#60

Closed
is0692vs wants to merge 1 commit intomainfrom
test/year-in-review-utils-14185050714145168185
Closed

🧪 add tests for yearInReviewUtils functions#60
is0692vs wants to merge 1 commit intomainfrom
test/year-in-review-utils-14185050714145168185

Conversation

@is0692vs
Copy link
Contributor

🎯 What: The testing gap addressed: Missing tests for `src/lib/yearInReviewUtils.ts` functions.
📊 Coverage: What scenarios are now tested:

  • `buildHourlyHeatmapFromCommitDates`: valid dates, invalid date handling, empty arrays.
  • `getMostActiveHour`: regular inputs, all-zero heatmaps, ties.
  • `getMostActiveDayFromCalendar`: valid counts, <=0 counts, empty calendars, ties.
    Result: The improvement in test coverage: 10 new tests added to thoroughly cover pure functions, catching edge cases securely without complex mock requirements.

PR created automatically by Jules for task 14185050714145168185 started by @is0692vs

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Mar 13, 2026 6:29am

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of the 'Year in Review' utility functions by introducing comprehensive unit tests. The added tests ensure the correct behavior of functions responsible for building hourly heatmaps and identifying most active periods, covering various edge cases and improving overall code reliability.

Highlights

  • New Test File Added: A new test file, src/lib/__tests__/yearInReviewUtils.test.ts, has been added to the codebase.
  • Increased Test Coverage: Ten new tests were introduced to thoroughly cover the pure functions within src/lib/yearInReviewUtils.ts, specifically buildHourlyHeatmapFromCommitDates, getMostActiveHour, and getMostActiveDayFromCalendar.
  • Edge Case Handling: The new tests include scenarios for valid inputs, invalid date handling, empty arrays, all-zero heatmaps, and tie-breaking logic for active hours and days.
Changelog
  • src/lib/tests/yearInReviewUtils.test.ts
    • Added new test file for yearInReviewUtils functions.
Activity
  • Pull request created automatically by Jules for task 14185050714145168185, initiated by @is0692vs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Summary by CodeRabbit

テスト

  • 年間レビュー機能の包括的なユニットテストを追加し、時間別分析、最もアクティブな時間帯の検出、最もアクティブな曜日の判定の信頼性を向上させました。

Walkthrough

yearInReviewUtilsの包括的なユニットテストスイートが追加されました。buildHourlyHeatmapFromCommitDates、getMostActiveHour、getMostActiveDayFromCalendarの3つの関数に対するテストケースを含みます。空入力、不正なデータ、タイブレーキングロジックをカバーしています。

Changes

Cohort / File(s) Summary
Test Suite Addition
src/lib/__tests__/yearInReviewUtils.test.ts
包括的なユニットテストスイート追加。buildHourlyHeatmapFromCommitDates、getMostActiveHour、getMostActiveDayFromCalendarの3関数に対するテストケース107行分を実装。空入力処理、不正なデータの無視、正確なカウント集計、タイブレーキングロジックをカバー。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 テストの束ねられて
ユーティリティを守る道
空と無効もしっかり確認
時間と日付を正確に数えて
バグなき日々へ跳ねていく

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは絵文字を含みますが、主な変更内容(yearInReviewUtilsの関数に対するテスト追加)を明確に説明しています。
Description check ✅ Passed 説明は変更内容と完全に関連しており、追加されたテストの詳細なカバレッジとシナリオをいくつか例を挙げて説明しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/year-in-review-utils-14185050714145168185
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a solid set of tests for the yearInReviewUtils functions, covering a good range of scenarios including empty inputs, invalid data, and tie-breaking logic. The tests are well-structured and improve the project's code coverage. I've added a few suggestions to enhance the assertions in the tests for buildHourlyHeatmapFromCommitDates. By comparing against a complete expected data structure instead of spot-checking values, the tests can be made more robust and declarative.

Comment on lines +11 to +15
expect(heatmap.length).toBe(7);
heatmap.forEach(day => {
expect(day.length).toBe(24);
day.forEach(hour => expect(hour).toBe(0));
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current way of checking if the heatmap is all zeros is a bit verbose. You can make this assertion more concise and declarative by comparing it to an expected zero-filled 2D array using toEqual. This also implicitly checks the dimensions of the inner arrays, making the test more robust.

Suggested change
expect(heatmap.length).toBe(7);
heatmap.forEach(day => {
expect(day.length).toBe(24);
day.forEach(hour => expect(hour).toBe(0));
});
expect(heatmap).toEqual(Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)));

Comment on lines +20 to +22
heatmap.forEach(day => {
day.forEach(hour => expect(hour).toBe(0));
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check for an all-zero heatmap can be more concise. Also, it currently doesn't verify the dimensions of the heatmap array. Using toEqual with an expected zero-filled array would make the test more robust by checking dimensions and values in a single, declarative assertion.

        expect(heatmap).toEqual(Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)));

Comment on lines +39 to +45
expect(heatmap[0][12]).toBe(1);
expect(heatmap[1][14]).toBe(2);
expect(heatmap[6][23]).toBe(1);

// Check that other arbitrary cells are 0
expect(heatmap[0][0]).toBe(0);
expect(heatmap[3][12]).toBe(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking individual cells is a good start, but it doesn't guarantee that other cells weren't unintentionally modified. A more robust approach is to compare the entire resulting heatmap with a fully defined expected heatmap. This ensures the function produces the exact output required and has no side effects on other parts of the data structure.

        const expected = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0));
        expected[0][12] = 1;
        expected[1][14] = 2;
        expected[6][23] = 1;
        expect(heatmap).toEqual(expected);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/__tests__/yearInReviewUtils.test.ts`:
- Around line 12-15: The test uses arrow callbacks with implicit returns inside
heatmap.forEach which causes the expect(...) expressions to be implicitly
returned; change the callbacks to use block bodies without returning values
(e.g., replace heatmap.forEach(day => { ... }) and the inner day.forEach(hour =>
{ expect(hour).toBe(0); }); or convert the loops to for...of loops) so that the
forEach callbacks do not return anything; update both occurrences (lines around
heatmap.forEach and the inner day.forEach).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c453e68-e776-4192-8ef7-d02b4c8d5d9e

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfdea1 and 603ac71.

📒 Files selected for processing (1)
  • src/lib/__tests__/yearInReviewUtils.test.ts

Comment on lines +12 to +15
heatmap.forEach(day => {
expect(day.length).toBe(24);
day.forEach(hour => expect(hour).toBe(0));
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

forEachのコールバックが値を返しています。

静的解析ツール(Biome)が指摘している通り、forEachのコールバックは値を返すべきではありません。expect(hour).toBe(0)の戻り値が暗黙的に返されています。テストの動作には影響しませんが、コードの意図を明確にするために修正することを推奨します。

♻️ 修正案
     it("returns a 7x24 heatmap of zeros for an empty array", () => {
         const heatmap = buildHourlyHeatmapFromCommitDates([]);
         expect(heatmap.length).toBe(7);
         heatmap.forEach(day => {
             expect(day.length).toBe(24);
-            day.forEach(hour => expect(hour).toBe(0));
+            day.forEach(hour => {
+                expect(hour).toBe(0);
+            });
         });
     });

     it("ignores invalid date strings", () => {
         const heatmap = buildHourlyHeatmapFromCommitDates(["invalid-date", "not-a-date"]);
         heatmap.forEach(day => {
-            day.forEach(hour => expect(hour).toBe(0));
+            day.forEach(hour => {
+                expect(hour).toBe(0);
+            });
         });
     });

Also applies to: 20-22

🧰 Tools
🪛 Biome (2.4.6)

[error] 14-14: This callback passed to forEach() iterable method should not return a value.

(lint/suspicious/useIterableCallbackReturn)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/__tests__/yearInReviewUtils.test.ts` around lines 12 - 15, The test
uses arrow callbacks with implicit returns inside heatmap.forEach which causes
the expect(...) expressions to be implicitly returned; change the callbacks to
use block bodies without returning values (e.g., replace heatmap.forEach(day =>
{ ... }) and the inner day.forEach(hour => { expect(hour).toBe(0); }); or
convert the loops to for...of loops) so that the forEach callbacks do not return
anything; update both occurrences (lines around heatmap.forEach and the inner
day.forEach).

@is0692vs
Copy link
Contributor Author

This PR is being closed as superseded by #61. Similar test changes were consolidated there, and the valid review feedback was incorporated in the consolidated branch so review and CI can proceed in one place.

@is0692vs is0692vs closed this Mar 14, 2026
@google-labs-jules
Copy link
Contributor

This PR is being closed as superseded by #61. Similar test changes were consolidated there, and the valid review feedback was incorporated in the consolidated branch so review and CI can proceed in one place.

Understood. Acknowledging that this work is now superseded by #61 and stopping work on this task.

is0692vs added a commit that referenced this pull request Mar 14, 2026
…6584521533216652745

📦 [Consolidated] PR #60, #62~#65 のテスト統合・レビュー指摘対応
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant